#!/usr/bin/env python
#coding:utf-8
#Code by Mango

# 主启动文件
# 框架上借用了MST

from libs.geCache import *

cache.start()  # 数据库的初始化,欢迎界面
#updateplu = updateplu(cache.getplunums("all"))
#updatemst = updatemst()
                                     
if __name__=='__main__':
    try:
        while 1:
            cache.printge()
            cmd=raw_input('>')
            if   cmd == 'help':  #帮助信息 OK
                cache.mainhelp()
            elif cmd == 'exit':  #退出 OK
                cache.mainexit()
            elif cmd == 'cls' :  #清屏 OK
                cache.cls()
            elif cmd == 'use':  #使用插件
                cache.usage("use")
            elif cmd == 'show':  #显示插件列表 OK
                cache.usage("show")  
            elif cmd == 'search':   #搜索
                cache.usage("search")
            elif cmd == 'searchip':
                cache.usage("searchip")
            elif cmd == 'banner':  #欢迎画面 OK 这个暂时取消了,太花哨
                cache.banner()
            #elif cmd == 'update':  # 在线更新  这个功能暂时没有
                #cache.usage("update")
            elif len(cmd.split(" ")) == 2:
                cnd = cmd.split(" ")
                c   = cnd[0]
                g   = cnd[1]
                if c == 'search':
                    if len(g)>0 and len(g.split(" "))>0:
                        cache.search(g)
                    else:
                        cache.usage("search")
                elif c == 'searchip':
                    if len(g)>0 and len(g.split(" "))>0:
                        cache.search_host(g)
                    else:
                        cache.usage("searchip")
                elif  c == 'show':
                    if   g == 'server':
                        cache.showplus('server')
                    #elif g == 'payload':
                        #cache.showplus('payload')
                    elif g == 'multi':
                        cache.showplus('multi')
                    elif g == 'all':
                        cache.showplus('all')
                    elif g == 'host':
                        cache.showplus('host')
                    elif g == 'pc':
                        cache.showplus('pc')
                    else:
                        cache.usage("show")
                elif  c == 'use':
                    if len(g) > 0 or len(g.split(" ")) > 0:
                        cache.load(g)
                    else:
                        cache.usage("use")
#                elif  c == 'update':
#                    if len(g) >0 or len(g.split(" ")) > 0:
#                        if g == "mst":
#                            updatemst.checkupdate()
#                        elif g == "plugins":
#                            updateplu.checkupdate()
#                        else:
#                            cache.usage("update")
#                    else:
#                        cache.usage("update")
                elif  len(cmd) > 0:
                    cache.execmd(cmd)
            elif len(cmd) > 0:
                cache.execmd(cmd)
    except KeyboardInterrupt:
        cache.mainexit()
    except Exception,e:
        cache.errmsg(e)